<?php

namespace App\Enums\OpenShop\InvestmentPromotion;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application;

class UserContractEnum
{
    const CONTRACT_PERSONAL = 1;
    const CONTRACT_COMPANY  = 2;

    /**
     * 签约主体
     */
    const CONTRACTORS = [
        1 => "个人",
        2 => "公司",
    ];

    const CONTRACT_TYPE_1 = 1;
    const CONTRACT_TYPE_2 = 2;
    const CONTRACT_TYPE_3 = 3;
    const CONTRACT_TYPE_4 = 4;
    const CONTRACT_TYPE_5 = 5;
    const CONTRACT_TYPE_6 = 6;
    const CONTRACT_TYPE_7 = 7;
    const CONTRACT_TYPE_8 = 8;
    const CONTRACT_TYPE_9 = 9;

    /**
     * 签约类型
     */
    const CONTRACT_TYPE = [
        self::CONTRACT_TYPE_1 => "新店加盟",
        self::CONTRACT_TYPE_2 => "老店裂变",
        self::CONTRACT_TYPE_3 => "解约合同v3",
        self::CONTRACT_TYPE_4 => "解约合同v4",
        self::CONTRACT_TYPE_5 => "解约合同-7天冷静期",
        self::CONTRACT_TYPE_6 => "【门店解约】-【分账模式】-【3%】-【20230704】",
        self::CONTRACT_TYPE_7 => "【门店解约】-【分账模式】-【10%】-【20230704】",
        self::CONTRACT_TYPE_8 => "续签合同",
        self::CONTRACT_TYPE_9 => "新店加盟 - 分账模式(个体户) - v1",
    ];

    const CONTRACT_TYPE_3_KEY = "contract.cancelContract.v3";
    const CONTRACT_TYPE_4_KEY = "contract.cancelContract.v4";
    const CONTRACT_TYPE_5_KEY = "contract.cancelContract.v5";
    const CONTRACT_TYPE_6_KEY = "contract.cancelContract.v6";
    const CONTRACT_TYPE_7_KEY = "contract.cancelContract.v7";
    const CONTRACT_TYPE_8_KEY = "contract.renewContract.v8";
    const CONTRACT_TYPE_9_KEY = "contract.newContract.selfEmployed.v1";

    /**
     * 签约主体
     */
    const IS_DOWN_PAYMENT = [
        1 => "否",
        2 => "是",
    ];

    /**
     * 获取契约锁配置信息
     *
     * @param int $type
     * @return Repository|Application|mixed
     * @throws \Exception
     */
    public static function getContractTypeConfig(int $type)
    {
        $constKey = "CONTRACT_TYPE_{$type}_KEY";
        if (defined(vsprintf("%s::%s", [self::class, $constKey]))) {
            $contractType = (new \ReflectionClass(self::class))->getconstant($constKey);
        } else {
            throw new \Exception(vsprintf("获取契约锁配置失败 未定义 %s::%s 常量信息", [self::class, $constKey]));
        }
        return config("qiyuesuo.{$contractType}");
    }

}
